/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cegg.graph.restriction;

import cegg.graph.vertex.ReasonVertex;
import java.awt.Graphics;
import java.util.Set;

/**
 *
 * @author kumper
 */
public class ExactOneRestriction extends Restriction {

    public static final String LABEL = "O";

    public ExactOneRestriction(Set<ReasonVertex> set) {
        super(set);
    }

    public ExactOneRestriction(ReasonVertex vertex1, ReasonVertex vertex2) {
        super(vertex1, vertex2);
    }

    public void paint(Graphics g)
    {
        int minX = 999999999;
        int maxX = 0;
        for (final ReasonVertex v : this.getVertexSet())
        {
            if (v.getPositionX() > maxX) maxX = v.getPositionX();
            if (v.getPositionX() < minX) minX = v.getPositionX();
        }
        int minY = 999999999;
        int maxY = 0;
        for (final ReasonVertex v : this.getVertexSet())
        {
            if (v.getPositionY() > maxY) maxY = v.getPositionY();
            if (v.getPositionY() < minY) minY = v.getPositionY();
        }
        int x = (minX+(maxX-minX)/2)-30;
        int y = minY+(maxY-minY)/2;

        for (final ReasonVertex v : this.getVertexSet())
        {
            g.drawLine(x, y, v.getPositionX(), v.getPositionY());
        }

        g.drawString(LABEL, x-15, y);
    }

}
